package com.yjhb.android.sbz.mvp.bidding;

import com.yjhb.android.sbz.entity.ManagerTask;
import com.yjhb.android.sbz.entity.TaskInfo;
import com.yjhb.android.sbz.enums.TaskState;
import com.yjhb.android.sbz.http.HttpObserver;
import com.yjhb.android.sbz.http.HttpTool;
import com.yjhb.android.sbz.mvp.ConventionPresenter;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建者 zx
 * 创建时间 2020/12/16 16:43
 */
public class BiddingTaskListPresenter extends ConventionPresenter<BiddingTaskListView> {
    private final String TAG = "BiddingTaskListPresenter";

    @Override
    protected void onDestroy() {

    }

    public BiddingTaskListPresenter(BiddingTaskListView biddingTaskListView) {
        super(biddingTaskListView);
    }


    public void getTaskList(int page, final int current) {
        HttpTool.request(model.getManagerTaskList(TaskState.TASK_STATE_DISPLAY.getState(), null,
                page, current), new HttpObserver<List<ManagerTask>>() {
            @Override
            public void onResult(List<ManagerTask> data) {
                List<TaskInfo> tasks = new ArrayList<>();
                if (data != null) {
                    for (int i = 0; i < data.size(); i++) {
                        tasks.add(data.get(i).getTask());
                    }
                }
                if (view != null) {
                    if (current == 1) {
                        view.onRefresh(tasks);
                    } else {
                        view.onLoad(tasks);
                    }
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }


}
